import pygtk
pygtk.require('2.0')
import gtk
# import os, sy
import os, sys

from yadict.gui.findpage import FindPage
from yadict.gui.databasepage import DatabasePage
from yadict.gui.basegtkwindow import BaseGtkWindow
from yadict.util.sqlutil import openDatabase

class YADictWindow(BaseGtkWindow):
        
    def buildLayout(self, yadictData):

        notebook = gtk.Notebook()
        notebook.set_tab_pos(gtk.POS_TOP)
        notebook.show()
               
        connection = None
        if yadictData.defaultDatabase != None:
            connection = openDatabase(yadictData.repositoryDatabase + "/" + yadictData.defaultDatabase)
            yadictData.setConnection(connection,yadictData.defaultDatabase)
            

        # we pass connection on findPage
        # check of existence inside it
        findPage = FindPage(yadictData)
        databasePage = DatabasePage(yadictData)

        notebook.append_page(findPage, gtk.Label("  Find  "))
        notebook.append_page(databasePage, gtk.Label("  DB  "))

        self.window.add(notebook)
        
    def __init__(self, yadictData):
        
        BaseGtkWindow.__init__(self)
        
        # Sets the border width of the window.
        self.window.set_border_width(5)
        
        # title
        self.window.set_title("YADict")
        
        self.buildLayout(yadictData)
        
        # size
        self.window.set_default_size(480,640)
        
        self.window.show()